#ifndef M0WIG_H
#define M0WIG_H

#include <QWidget>
#include <QDialog>
#include <QTcpServer>
#include <QTcpSocket>
#include <QUdpSocket>
#include <QDebug>
#include <QTextStream> // 文本流类
#include <QString>
#include <QMessageBox>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include "mqtt/qmqtt.h"
#include <QJsonArray>
#include <QCoreApplication>
#include <QFile>
#include <QByteArray>
#include <QFileInfo>
#include <QTimer>
#include <QPainter>

namespace Ui {
class M0Wig;
}

class M0Wig : public QWidget
{
    Q_OBJECT

public:
    explicit M0Wig(QWidget *parent = 0);
    ~M0Wig();
    // TCP连接
    void bindPort();
    void socketMqtt(QByteArray);
    void socketMqtt2(QByteArray);
    void Send1Slot();

    QHostAddress peerAddr;//上报端ip地址
    quint16 targetPort; //目标端口


private:
    Ui::M0Wig *ui;
    QUdpSocket *udpsocket = NULL;
    QTcpSocket *socket1;// 客户端对象1
    QTcpSocket *socket2;// 客户端对象2


    QTimer *timer;//心跳检测
    QTimer *timer1;//心跳检测

    void paintEvent(QPaintEvent * event);


signals:
    void con(QByteArray);



private slots:
    void on_btnBroadcast_clicked();
    void onSocketReadyRead();


    // TCP相关
    void socketRead();
    void socket2Read();

    // TCP连接
    void tcpClient();
    void socketSend();
    void socket2Send();

    //心跳包
   void sendHeartbeat();
   //上报模式控制
   void control(int);
   //刷新
   void xin();
};

#endif // M0WIG_H
